const user ={
  state:{
    consumerId: '', //用户id
    username:'' ,//用户名
    avatar:false,//用户头像
  },
  getters : {
    consumerId:state =>{
      let consumerId = state.consumerId
      if (!consumerId){
        consumerId = JSON.parse(localStorage.getItem('consumerId'))
      }
      return consumerId
    },
    username:state =>{
      let username = state.username
      if (!username){
        username = JSON.parse(localStorage.getItem('username'))
      }
      return username
    },
    avatar:state =>{
      let avatar = state.avatar
      if (!avatar){
        avatar = JSON.parse(localStorage.getItem('avatar'))
      }
      return avatar
    },

  },
  mutations:{
    setConsumerId:(state,consumerId)=>{
      state.consumerId = consumerId
      localStorage.setItem('consumerId',JSON.stringify(consumerId))
    },
    setUsername:(state,username)=>{
      state.username = username
      localStorage.setItem('username',JSON.stringify(username))
    },
    setAvatar:(state,avatar)=>{
      state.avatar = avatar
      localStorage.setItem('avatar',JSON.stringify(avatar))
    },
  }
}
export default user

